## Figure 2 ##
library(dplyr)
library(ggplot2)
## Import the "wv7_cs.rdata" file ##
data<-rio::import(file.choose())
## Define postmat, which represents the postmaterialism index for individuals. 1=most materialist, 4=most postmaterialist ##
data$postmat<-NA
data$postmat[which((data$Q154==1 & data$Q155==3) | (data$Q154==3 & data$Q155==1))]<-0
data$postmat[which((data$Q154==1 & data$Q155==2) | (data$Q154==1 & data$Q155==4) | (data$Q154==3 & data$Q155==2) | (data$Q154==3 & data$Q155==4) | (data$Q154==2 & data$Q155==1) | (data$Q154==2 & data$Q155==3) | (data$Q154==4 & data$Q155==1) | (data$Q154==4 & data$Q155==3))]<-1
data$postmat[which((data$Q154==2 & data$Q155==4) | (data$Q154==4 & data$Q155==2))]<-2
table(data$postmat)

state_postmat<-data %>% group_by(B_COUNTRY_ALPHA)
state_postmat <- state_postmat %>% summarise(
  mean_postmat = mean(postmat,na.rm = TRUE)
)
state_postmat$GDPPC<-c(40897,8442,51812,1969,3143,6797,43242,13232,10500,5333,26624,45724,5600,3548,936,17677,
                       4603,46324,3870,2283,4158,4283,40113,9056,1174,31489,4891,86118,8347,1400,10402,2097,1905,
                       41792,1194,6127,3299,32291,12896,10127,59798,7666,7189,859,3320,8538,28371,3727,63544,2786,1128)

state_postmat$ln_gdppc <- log(state_postmat$GDPPC)
ggplot(state_postmat, aes(x=ln_gdppc,y=mean_postmat)) + geom_point(size=3) +
  geom_text(data=subset(state_postmat,GDPPC %in% c(10500,46324,28371)),aes(ln_gdppc,mean_postmat,label=B_COUNTRY_ALPHA),size=13) +
  scale_x_continuous(name = "log(GDP per capita)") +
  scale_y_continuous(name = "Post-materialism mean") +
  theme(axis.title = element_text(size=28),
        axis.text = element_text(size=28))

